//
//  LTFNetWorkingTool.m
//  NeteaseNews
//
//  Created by liutaifeng on 16/4/14.
//  Copyright © 2016年 liutaifeng. All rights reserved.
//

#import "LTFNetWorkingTool.h"

@implementation LTFNetWorkingTool
+ (void)toolWithUrl:(NSString *)strURL block:(void(^)(id result))block {
    NSURL *url = [NSURL URLWithString:strURL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (data == nil) {
            NSLog(@"网络错误");
        }
        else {
        dispatch_queue_t queue = dispatch_get_main_queue();
        dispatch_async(queue, ^{
            
            
            id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            block(result);
        });
        }
    }];
    [task resume];
}

@end
